home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 01 Manslow / GAPBILExample / CPS.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-10  |  2.0 KB  |  75 lines

  1. //GAPBILExample
  2. //Copyright John Manslow
  3. //29/09/2001
  4.  
  5. #ifndef _CPS_
  6. #define _CPS_
  7.  
  8. class CPS
  9. {
  10. public:
  11.  
  12.     CPS(        
  13.                     const unsigned long,            //Chromosome length
  14.                     const int * const                    //Gene type information
  15.                     );
  16.  
  17.     ~CPS();
  18.  
  19.     //Creates a new chromosome by randomly mutating the best so far
  20.     double *pdGetChromosomeForEvaluation(void);
  21.  
  22.     //Sets the fitness of the working chromosome. The PS works the same way as the GA 
  23.     //and PBIL. Get a chromosome using the above function, evaluate its fitness, and feed
  24.     //it back to the PS class using the function below
  25.     void SetFitness(const double);
  26.  
  27.     //Returns a pointer to the best chromosome discovered so far
  28.     double *pdGetBestChromosome(void);
  29.  
  30.     //Returns the performance of the best chromosome found so far
  31.     double dGetBestPerformance(void);
  32.  
  33.     //Load and save the status of the PS
  34.     int Save(const char*const);
  35.     int Load(const char*const);
  36.  
  37. private:
  38.     //These functions don't need to be called from outside the class to make the GA work
  39.     void Mutate(void);
  40.  
  41.     //Allocate and deallocate memory
  42.     void AllocateMemory(void);
  43.     void DeallocateMemory(void);
  44.  
  45.     //Create a random starting chromosome and resets search statistics
  46.     void InitialisePopulation(void);
  47.  
  48.     //Mutates the chromosome in the parameter list
  49.     //void Mutate(double * const);
  50.  
  51.     //The mutation rate sets the probability with which binary genes are muated (flipped)
  52.     double dMutationRate;
  53.  
  54.     //The step size controls the magnitude of mutations made to continuous genes
  55.     double dStepSize;
  56.  
  57.     //Chromosome length
  58.     unsigned long ulChromosomeLength;
  59.  
  60.     //Pointer to the working chromosome
  61.     double *pdGenes;
  62.  
  63.     //Pointer to a list of gene type indicators: 0=gene is binary, 1=gene is real
  64.     int *pnGeneTypes;
  65.  
  66.     //Storage for the fittest chromosome discovered so far and its fitness
  67.     double *pdBestChromosome;
  68.     double dBestFitness;
  69.  
  70.     //The number of iterations (i.e. number of fitness evaluations)
  71.     unsigned long ulIteration;
  72.  
  73. };
  74.  
  75. #endif